<?php

class PrjAction extends Action
{    

	/**
	 * PrjAction::_initialize()
	 * 
	 * @return
	 */
	public function _initialize()
    {
        checkLoginSession();		
		checkSec(1);
    }
	
	/**
	 * PrjAction::ctrPrj()
	 * @abstract 根据提交的商品url和其他信息，生成项目记录，插入多条记录到项目产品表
     * 上传活动图片到空间
     * 
	 * @return
	 */
     
	public function ctrPrj()
	{//dump($_POST);
    //print_r($_FILES['imgfile']);
	 
    if (!empty($_FILES))
    {
    
        //UPLOAD FILE
        import("ORG.Net.UploadFile");
        $upload = new UploadFile();
        $upload->maxSize = 3292200;
        $upload->allowExts = explode(',', 'jpg,gif,png,jpeg');        
        $upload->savePath = getcwd().'/Public/Uploads/';
        $upload->thumb = true;
        $upload->thumbPrefix = 's_'; 
        $upload->thumbMaxWidth = '120,60';
        $upload->thumbMaxHeight = '140,60';
        $upload->saveRule = uniqid();
        $upload->thumbRemoveOrigin = true;
        
        
        if (!$upload->upload())
        {
        $this->error($upload->getErrorMsg());
        } else
        {
        $uploadList = $upload->getUploadFileInfo();
        $imgname = $uploadList[0]['savename'];
        }  
        

        }
        //执行ok后，跳转回原来项目页面
        $cnt = 'myPrj';
        $this->assign('imgname', $imgname);
		$this->assign('content', "Public:".$cnt);			
	    $this->display('Public:panel');   

    }

public function checkPrj(){//检查项目id对于项目是不是信息全面，可以启动了，分支处理
    
    if(isset($_GET['id_gezi_prj']))
    {
    $this->assign('id_gezi_prj', $_GET['id_gezi_prj']);
    $status = isset($_GET['status'])?$_GET['status']:'beCreated';
    $rtArray = getPrjpdtList($status,$_GET['id_gezi_prj']);
    $rttary = getPrjList($status); 
	$prjList = $rttary['a'];$pageprj =$rttary['b']; 
    			    
    $prjpdtList = $rtArray['a'];$page =$rtArray['b']; 
    $this->assign('prjpdtList', $prjpdtList);
    //dump($prjpdtList);
    $this->assign('prjList', $prjList);
    
    $this->assign('describePrj', $prjList[0]['describePrj']);
    $this->assign('page', $page);   
    $this->display('Prj:execPrj');
   }
}

 public function addPrjInfo(){    
 if (!empty($_FILES))
   {$uprt = $this->up();
    //dump($uprt);
    //更新项目信息
    $nowGezi = isset($_POST['nowGezi'])?$_POST['nowGezi'] :0;
    $Prj =M('Prj');
    $data['describePrj'] = $_POST['describePrj'];
    $data['status'] ='tobeCheck';//已提交申请信息，等候系统批准
    $id_gezi_prj = $_POST['id_gezi_prj'];
    $rtt = $Prj->where("id_gezi_prj = $id_gezi_prj")->save($data);
    
    //添加申请项目执行的消息
    $msgs = '项目:'.$id_gezi_prj.'申请执行';
    $from_id_user = $_SESSION['UserInfo']['id'];
    $target = 'System';
    $msgkind = 'prjExecApply';
    $method='bs';
    $at1 ='id_gezi_prj:'.$id_gezi_prj;//附加一个项目id参数，这样能直接调用，查看项目申请情况
    $at2 ='用户名:'.$_SESSION['UserInfo']['name'];
    addMsg($msgs,$from_id_user,$target,$msgkind,$method,$at1,$at2);
     
    //更新项目产品，遍历参数
    $Prj_pdt =M('Prj_pdt');
    $id_gezi_prj_pdt = $_POST['id_gezi_prj_pdt'];      
    $pdtcnt = count($id_gezi_prj_pdt);    

    for($i=0;$i<$pdtcnt;$i++)
    {
    $data['productUrl'] = $_POST['productUrl'][$i];
    $Util = A("Util");
     
    $tbitem =$Util->getTaoItem($data['productUrl']);
    $couponTab = isset($_POST['couponTab'])?$_POST['couponTab']:0;
    //dump($tbitem);
    $data['pName'] =$tbitem[0];
    $data['pTprice'] = $tbitem[1];
    $data['pPic'] =  $tbitem[2];
    $data['couponTab'] = ($nowGezi>$couponTab)?($couponTab+1+$i):$nowGezi;
    $data['tCode'] =  $Util->getTcode();    
    $data['id_gezi_prj'] = $_POST['id_gezi_prj'];
    //$data['pNprice'] = $_POST['pNprice'];
    //$data['pSprice'] = $_POST['pSprice'];
    $describePrj = $_POST['describePrj'][$i];
         
    $data['prj_pic'] = $uprt[$i]['savename'];;
        
    $rtt1 = $Prj_pdt->where("id_gezi_prj_pdt = $id_gezi_prj_pdt[$i]")->save($data);
    }
   	$cnt = 'myPrj';
    $this->assign('content', "Public:".$cnt);			
	$this->display('Public:panel');     
   }
   else
   {
    header('Content-Type:text/html; charset=utf-8'); //防止出现乱码    
    echo "请选择上传文件";
    }
 }
 
    public function upload(){
          if (!empty($_FILES))
            {
              $rt = $this->up();
            }
          else
              echo "请选择上传文件";
    }
  private function up(){
    
    //echo "begin upload";
    import("ORG.Net.UploadFile");
    $upload = new UploadFile();
    $upload->maxSize = 3292200;
    $upload->allowExts = explode(',', 'jpg,gif,png,jpeg');        
    //$upload->savePath = getcwd().'/Public/Uploads/';
    $upload->savePath = './Public/Uploads/';
    $upload->saveRule = 'uniqid';  
    $upload->allowTypes =array('image/png','image/jpeg','image/jpg','image/gif') ;           
    $upload->thumb = true;
    $upload->thumbPrefix = 'm_,s_'; 
    $upload->thumbMaxWidth = '120,60';
    $upload->thumbMaxHeight = '140,60';
    $upload->thumbRemoveOrigin = true;
    $upload->supportMulti =true;
            
    if (!$upload->upload())
    {
    $this->error($upload->getErrorMsg());
    } else
    {
    $uploadList = $upload->getUploadFileInfo();
    //$imgname = $uploadList[0]['savename'];
    //dump($uploadList);
    return $uploadList;
     } 
 }

//对指定prjid的pdt，显示并修改提交 
    public function upPrjpdt()
    {
    $id_gezi_prj = $_GET['id_gezi_prj'] ; 
    $id_task = $_GET['taskid'];
    $nowGezi = $_GET['nowGezi'];
    $status = isset($_GET['status'])?$_GET['status']:NULL;
    $pdts = getPrjpdtList($status,$id_gezi_prj);    
    $this->assign('id_task', $id_task);
    $this->assign('nowGezi', $nowGezi);
    
    
    $this->assign('describePrj', $pdts['a'][0]['describePrj']);    
    $this->assign('prjpdtlistUp',$pdts['a']);
    $this->display('Prj:upPrjpdt');
    }
    
    //显示选择项目界面，回调显示项目产品信息更新界面
    public function execPrjS()
    {
    $nowGezi = isset( $_GET['nowGezi'])? $_GET['nowGezi']:0;
    $this->assign('nowGezi', $nowGezi); 
    $this->display('Prj:execPrj');   
    }
}
?>